/**
 *  Copyright (C) 2008-2013  Telosys project org. ( http://www.telosys.org/ )
 *
 *  Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *          http://www.gnu.org/licenses/lgpl.html
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.telosys.common.data;

import org.telosys.common.TelosysRuntimeException;

/**
 * BeanList management methods
 * 
 * @author Laurent Guerin
 * 
 */
public class BeanListManager 
{
    //-----------------------------------------------------------------------------
    /**
     * Returns true if the given class is a subclass of GenericVOList
     * @param cl
     * @return true if the given class is a VOList
     */
    public static boolean isBeanListClass(Class<?> cl)
    {
        if ( cl != null )
        {
	        // Same as, or super class, or super interface of ( cl )
	        if ( BeanList.class.isAssignableFrom(cl) )
	        {
	            return true;
	        }
        }
        return false;
    }
    
    //-----------------------------------------------------------------------------
    /**
     * Returns true if the given object is not null and is an instance of GenericVOList
     * @param obj
     * @return true if the given object is a VOList
     */
    public static boolean isBeanListClass(Object obj)
    {
        if ( obj != null )
        {
            if ( obj instanceof BeanList )
            {
                return true;
            }
        }
        return false;
    }
    
    //-----------------------------------------------------------------------------
    /**
     * Creates a GenericVOList instance of the given class 
     * @param cl the class to instanciate (supposed to be a subclass of GenericVOList)
     * @return the instance created
     * @throws TelosysRuntimeException if the instance cannot be created or if the class is not a GenericVOList
     */
    //public static GenericVOList createBeanListInstance(Class<?> cl)
    public static BeanList<Object> createBeanListInstance()
    {
//        if ( cl != null )
//        {
//            try
//            {
//                Object obj = cl.newInstance();
//    	        if ( obj instanceof GenericVOList )
//    	        {
//    	            return (GenericVOList) obj ;
//    	        }
//    	        else
//    	        {
//    	            throw new TelosysRuntimeException("createVOListInstance(" + cl.toString() +") : not a VOList class.");
//    	        }
//            } catch (InstantiationException e)
//            {
//                throw new TelosysRuntimeException("createVOListInstance(" + cl.toString() +") : InstantiationException", e) ;
//            } catch (IllegalAccessException e)
//            {
//                throw new TelosysRuntimeException("createVOListInstance(" + cl.toString() +") : IllegalAccessException", e) ;
//            }
//        }
//        else
//        {
//            throw new TelosysRuntimeException("createVOListInstance(null) : the class is null.");
//        }       
    	BeanList<Object> beanList = new BeanList<Object>(Object.class);
    	return beanList ;
    }

}
